﻿package mortal.game.scene3D.display3d.text3d.staticText3d.action
{
    import flash.geom.*;
    import frEngine.*;

    public class Action2MoveFun extends ActionMoveBase
    {
        private var _curOffY:Number = 0;
        private var _curOffX:Number = 0;
        private var _alpha:Number = 0.99;
        private var _scale:Number = 100;
        private var _isStarted:Boolean = false;
        private var _index:int = 0;
        private var startPos:Vector3D;
        private static const c_totalTime:int = 80;
        private static const c_interval:int = 10;
        private static const Vy:Number = 3;
        private static const c_x1t:int = 30;
        private static const c_apht:int = 60;
        private static const c_xs:Number = 90;
        private static const c_xa:Number = 0.2;
        private static const c_xv:Number = 6;
        private static const offsetXValue:int = 80;
        private static const offsetYValue:int = 50;
        private static var startActionFrame:uint = 0;
        private static var lastShowItemIndex:int = 0;
        private static var lastEndItemIndex:int = 0;

        public function Action2MoveFun()
        {
            return;
        }// end function

        override public function update(param1:int, param2:Vector3D) : Boolean
        {
            if (!this._isStarted)
            {
                this._index = getIndex();
                this._isStarted = true;
                if (this._index < 0)
                {
                    this._isStarted = false;
                    return false;
                }
            }
            param1 = TimeControler.stageFrame - startActionFrame - this._index * c_interval;
            if (param1 < 0)
            {
                param2.x = 0;
                param2.y = 0;
                param2.z = 0 + 100;
                return true;
            }
            if (param1 > c_totalTime)
            {
                this._scale = 100;
                this._isStarted = false;
                lastEndItemIndex = this._index;
                return false;
            }
            this._curOffY = param1 * Vy + offsetYValue;
            if (param1 < c_x1t)
            {
                this._curOffX = c_xv * param1 - 0.5 * c_xa * param1 * param1 + offsetXValue;
            }
            else
            {
                this._curOffX = c_xs + offsetXValue;
            }
            if (param1 < c_apht)
            {
                this._alpha = 0.99;
            }
            else
            {
                this._alpha = 0.99 * (c_totalTime - param1) / (c_totalTime - c_apht);
            }
            param2.x = this._curOffX;
            param2.y = this._curOffY;
            param2.z = this._alpha + this._scale;
            return true;
        }// end function

        private static function getIndex() : int
        {
            var _loc_1:* = TimeControler.stageFrame;
            var _loc_2:* = _loc_1 - startActionFrame - lastShowItemIndex * c_interval;
            if (lastEndItemIndex == lastShowItemIndex)
            {
                startActionFrame = _loc_1;
                lastShowItemIndex = 0;
                _loc_2 = 0;
                lastEndItemIndex = 0;
            }
            var _loc_3:int = 1;
            if (_loc_2 > 0)
            {
                _loc_3 = Math.ceil(_loc_2 / c_interval);
            }
            if (lastShowItemIndex + _loc_3 - lastEndItemIndex > 15)
            {
                return -1;
            }
            lastShowItemIndex = lastShowItemIndex + _loc_3;
            return lastShowItemIndex;
        }// end function

    }
}
